package com.neusoft.yuejian_6.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.javabean.Order;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Q on 2017/11/1.
 */

public class OrderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private Context mContex;
    private List mDataList;
    private OrderAdapter.ViewHolder viewHolder;
    private LayoutInflater mLayoutInflater;

    public OrderAdapter(Context mContext, List mDataList) {
        this.mContex =  mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).
                inflate(R.layout.cardview_order, parent, false);
        return new OrderAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Order entity = (Order) mDataList.get(position);
        if (null == entity)
            return;
        OrderAdapter.ViewHolder viewHolder = (OrderAdapter.ViewHolder) holder;
        viewHolder.order_intro.setText(entity.getOrder_intro());
        viewHolder.order_time.setText(entity.getOrder_time());
        viewHolder.order_name.setText(entity.getOrder_name());
        //Log.d("s","post_time");
        String order_pic = "http://10.0.2.2/neu1_yuejian/Public/Admin/photo/"+entity.getOrder_pic();
        //System.out.print("pic");
        if (!order_pic.equals("")) {
            Picasso.with(mContex).load(order_pic).error(R.drawable.ic_add).into(viewHolder.order_pic);
        }

//        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Bundle bundle=new Bundle();
//                bundle.putInt("t_id",entity.getT_id());
//                bundle.putString("t_name",entity.getT_name());
//                bundle.putInt("t_price",entity.getT_price());
//                bundle.putString("t_address",entity.getT_address());
//                bundle.putString("t_time",entity.getT_time());
//                bundle.putString("t_picture",entity.getT_picture());
//                bundle.putString("t_phone",entity.getT_phone());
//                Intent intent=new Intent(mContex, TrainDetailActivity.class);
//                intent.putExtras(bundle);
//                mContex.startActivity(intent);
//            }
//        });
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView order_pic;
        TextView order_time,order_intro,order_name;

        public ViewHolder(View itemView) {
            super(itemView);
            order_time = (TextView) itemView.findViewById(R.id.order_time);
            order_intro = (TextView) itemView.findViewById(R.id.order_intro);
            order_name = (TextView) itemView.findViewById(R.id.order_name);
            order_pic = (ImageView) itemView.findViewById(R.id.order_pic);
        }
    }
}